package com.wanbangee.marksystem.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wanbangee.marksystem.entities.USubjectClassRelation;
import com.wanbangee.marksystem.entities.UTeacher;
import com.wanbangee.marksystem.service.UClassSubjectRelationService;

@RestController
@RequestMapping("subjectAndClassRelation")
public class UClassSubjectRelationController {

	@Autowired
	private UClassSubjectRelationService uClassSubjectRelationService;
	
	//根据班级ID查询对应的学科
	@GetMapping("selectSubjectByClaNm")
	public Map<String, Object> selectSubjectByClaId(String claNm){
		Map<String, Object> map=new HashMap<>();
		List<USubjectClassRelation> lists =this.uClassSubjectRelationService.selectUSubjectClassRelationByclaId(claNm);
		map.put("code", "1001");
		map.put("message", "接口成功");
		map.put("lists", lists);	
		return map;	
	}
	//根据学科id查询所有此学科老师信息
	@GetMapping("selectTeaBySubIdAndSchId")
	public Map<String, Object> selectTeaBySubIdAndSchId(Integer subId,Integer schId){
		Map<String, Object> map=new HashMap<>();
		List<UTeacher> listTea=this.uClassSubjectRelationService.selectTeaBySubIdAndSchId(subId, schId);
		map.put("code", "1001");
		map.put("message", "接口成功");
		map.put("lists", listTea);	
		return map;	
	}
	//新增学科与班级的关系
	@PostMapping("insertSubjectAdnClassRelation")
	public Map<String, Object> insertSubjectAdnClassRelation(USubjectClassRelation uSubjectClassRelation) {
		Map<String, Object> map=new HashMap<>();
		this.uClassSubjectRelationService.insertSubjectAdnClassRelation(uSubjectClassRelation);
		map.put("code", "1001");
		map.put("message", "接口成功");
		return map;	
	}
	
	/**
	 * 根据relId删除此班级该任课老师的关系
	 * @param uSubjectClassRelation
	 * @return
	 */
	@DeleteMapping("deleteTeaByrelId")
	public Map<String, Object> deleteTeaByrelId(Integer relId) {
		Map<String, Object> map=new HashMap<>();
		Integer rel=this.uClassSubjectRelationService.deleteTeaByrelId(relId);
		if(rel==1) {
		map.put("code", "1001");
		map.put("message", "接口成功");
		return map;	
		}
		map.put("code", "1002");
		map.put("message", "接口失败");
		return map;	
	}
	
	/**
	 * //根据主键id查询此学科老师信息
	 *  //  修改前数据回显
	 * @param relId
	 * 
	 * @return
	 */
	
		@GetMapping("selectByrelId")
		public Map<String, Object>  selectByrelId(Integer relId){
			Map<String, Object> map=new HashMap<>();
			USubjectClassRelation uSubjectClassRelation=this.uClassSubjectRelationService.selectByrelId(relId);
			map.put("code", "1001");
			map.put("message", "接口成功");
			map.put("uSubjectClassRelation", uSubjectClassRelation);	
			return map;	
		}
	
		@PostMapping("updateUSubjectClassRelation")
		public Map<String, Object> updateUSubjectClassRelation(USubjectClassRelation uSubjectClassRelation){
			Map<String, Object> map=new HashMap<>();
			Integer rel=this.uClassSubjectRelationService.updateUSubjectClassRelation(uSubjectClassRelation);
			if(rel==1) {
				map.put("code", "1001");
				map.put("message", "接口成功");
				return map;	
				}
				map.put("code", "1002");
				map.put("message", "接口失败");
				return map;	
		}
		
	/*
	 * 调用年级管理-查询所有正常状态的学校
	 * */
	
	/*
	 * 调用班级管理-年级查询
	 * */
	
	/*
	 * 调用班级管理-班级查询，本功能传入的graId 不能为-1
	 * */
	
	
}
